package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.bike.dto.IdentityInfoDto;
import cn.com.chengmandian.bike.model.EbIdentityInfo;
import cn.com.chengmandian.bike.service.IEbIdentityInfoService;
import cn.com.chengmandian.core.common.constants.CommonConstant;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 电单车运营平台-身份信息 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-09-18
 */
@Api(tags = "身份信息配置")
@RestController
@RequestMapping("/identity/info")
public class EbIdentityInfoController {

    @Autowired
    private IEbIdentityInfoService identityInfoService;

    @ApiOperation("列表")
    @GetMapping("/list")
    public AjaxResult<List<EbIdentityInfo>> getList(IdentityInfoDto dto) {
        if(StrUtil.isNotBlank(dto.getIds())) {
            return AjaxResult.success(identityInfoService.list(new LambdaQueryWrapper<EbIdentityInfo>()
                    .in(EbIdentityInfo::getId, Arrays.asList(dto.getIds().split(",")))
                    .eq(EbIdentityInfo::getIsEnabled, CommonConstant.ONE)
                    .last(" order by sort asc, id desc")));
        }else {
            return AjaxResult.success(identityInfoService.list(new LambdaQueryWrapper<EbIdentityInfo>()
                    .eq(EbIdentityInfo::getIsEnabled, CommonConstant.ONE)
                    .last(" order by sort asc, id desc")));
        }
    }
}
